import {combineReducers} from 'redux';
import Action from "../actions/types";
import main from "./main";
import order from "./order";
import cart from "./cart";
import user from "./user";


const reducers: Record<string, { initialState: any, handle: any }> = {
    main, order,cart,user
};

const combineResult: any = {};
Object.keys(reducers).forEach((item) => {
    combineResult[item] = (state: any = reducers[item].initialState, action: Action) => {
        return typeof reducers[item].handle[action.type] === "function"
            ? reducers[item].handle[action.type](state, action)
            : state;
    }
});
export default combineReducers(combineResult);
